package com.wtpaint.leetcode.查找表;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class WordPattern290 {

    public static boolean wordPattern(String pattern, String str) {
        String[] temp = str.split(" ");
        if (pattern.length() != temp.length) {
            return false;
        }

        Map<Character, String> res = new HashMap<>();
        for (int i = 0; i < temp.length; i++) {
            Character c = pattern.charAt(i);
            if (res.containsKey(c)) {
                String s = res.get(c);
                if (!s.equals(temp[i])) {
                    return false;
                }
            } else {
                if (res.containsValue(temp[i])) {
                    return false;
                }
                res.put(c, temp[i]);
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(" " + wordPattern("abba", "dog cat cat dog1"));
    }

}
